﻿using RAP.Framework.Libary.DomTemplateBuilder.Element.Conditional;
using System;
using RAP.Framework.Libary.DomTemplateBuilder.Interface;

namespace RAP.Framework.Libary.DomTemplateBuilder.Handler.Conditional
{
	/// <summary>
	/// ElseIf节点的Handler
	/// </summary>
	public class ElseIfHandler : DynamicHandler, IConditionHandler
    {
        public virtual new ElseIf Element
        {
            get
            {
                return base.Element as ElseIf;
            }
        }

        public virtual bool IsCondition ( object rootParamObject, object parentParamObject, ITemplateRenderContext context )
        {
            var handler = this.Element.GetExpressionHandler( rootParamObject, parentParamObject, context );
            if ( handler == null )
            {
                throw new NullReferenceException( "If节点的表达式语法错误，获取表达式Handler失败！" );
            }
            return handler( rootParamObject, parentParamObject, context );
        }
    }
}
